<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCommentsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('comments', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->BigInteger('user_id')->nullable();
            $table->string('user_type')->nullable();
            $table->string('guest_name')->nullable();
            $table->string('guest_email')->nullable();
            $table->Integer("app_id");		 //原commentable_type
            $table->string("root_id");       //原commentable_id，uuid
            $table->text('comment');
            $table->boolean('approved')->default(true);
            $table->unsignedBigInteger('child_id')->nullable();

            $table->index(["user_id", "user_type"]);
            $table->index(["app_id", "root_id"]);

            $table->foreign('child_id')->references('id')->on('comments')->onDelete('cascade');
            $table->timestamps();
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('comments');
    }
}